package jbp.common.util;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtil {
    //http://www.cocoachina.com/articles/87845
    private static final ObjectMapper mapper = new ObjectMapper();

    public static <T>T toObject(String json, TypeReference<T> typeRef){
        T t = null;
        try {
            t = mapper.readValue(json, typeRef);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return t;
    }

    //java.util.List<Object> devices= JsonUtil.toObject(jsonString,
    //        new TypeReference<java.util.List<Object>>() {});

    //Object object= JsonUtil.toObject(jsonString, new TypeReference<Object>() {});
}
